package exa.unicen.edu.ringo.raccess.model.manager;

import java.io.IOException;

import exa.unicen.edu.ringo.raccess.utils.FileUtils;
import exa.unicen.edu.ringo.rmodel.bean.Configuration;
import exa.unicen.edu.ringo.rmodel.builder.ModelBuilder;

public class ConfigurationManager {

	public static ConfigurationManager instance = new ConfigurationManager();
	
	private Configuration configuration;
	
	public Configuration load(String file){
		
		try {

			String xml = FileUtils.readFileAsString(file);
			configuration = (Configuration) ModelBuilder.instance.marshal(Configuration.class, xml);
			return configuration;
		
		} catch (IOException e) {
			System.err.println("Could not load configuration from " + file);
			return this.get();
		}

	}	
	
	public Configuration clear(){
		configuration = new Configuration();
		return configuration;
	}
	
	public Configuration get(){
		if (configuration == null) { configuration = new Configuration(); }
		return configuration;
	}
	
	public Configuration set(Configuration configuration){
		this.configuration = configuration;
		return this.configuration;
	}
	

	
	
}
